# 调用知识库


import requests
from pprint import pprint
import json

class Knowledge:

    def __init__(self):
        self.base_url = r'http://180.184.65.98:38880/atomgit/'

    # 测试接口
    def test(self):
        url = self.base_url + 'metadata'
        resp = requests.get(url=url)
        print(resp.text)

    # 根据相似内容查找文章
    def search_paper(self, params):
        """
        Args:
            params = {
                "query": "yolov11",(检索相似的内容, 必选)
                "top_k": 5,(可选)
            }
        return distance, entity: paper_id, paper_title, chunk_id, chunk_text, original_filename
        """
        url = self.base_url + 'search_papers'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 根据paper_id查找
    def query_by_paper_id(self, params):
        "return paper_id, paper_title, chunk_id, chunk_text, original_filename"
        url = self.base_url + "query_by_paper_id"
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 根据标题查找
    def query_by_title(self, params):
        url = self.base_url + "query_by_title"
        resp = requests.get(url=url, params=params)
        resp = json.loads(resp.text)
        print(resp.text)

    def query_by_title_contain(self, params):
        url = self.base_url + "query_by_title_contain"
        resp = requests.get(url=url, params=params)
        print(resp.text)

    def query_by_chunk_contain(self, params):
        url = self.base_url + "query_by_chunk_contain"
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 找相似论文标题
    def query_by_title_like(self, params):
        """
        return 相似论文信息列表
        """
        url = self.base_url + "query_by_title_like"
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 关键词查找论文ID和标题
    def query_by_keyword(self, params):

        url = self.base_url + 'query_by_keyword'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 论文ID查找全文
    def query_whole_text_by_id(self, params):
        url = self.base_url + 'query_whole_text_by_id'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 论文标题查找全文
    def query_whole_text_by_title(self, params):
        url = self.base_url + 'query_whole_text_by_title'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 论文ID查找关键词
    def query_keywords_by_id(self, params):
        url = self.base_url + 'query_keywords_by_id'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 论文标题查找关键词
    def query_keywords_by_title(self, params):
        url = self.base_url + 'query_keywords_by_title'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 查看关键词统计
    def keywords_metadata(self):
        url = self.base_url + 'keywords_metadata'
        resp = requests.get(url=url)
        print(resp.text)

    # 搜索标题中包含特定关键词的论文元数据
    def query_paper_metadata_that_title_contain(self, params):
        url = self.base_url + 'query_paper_metadata_that_title_contain'
        resp = requests.get(url=url, params=params)
        print(resp.text)

    # 查找与输入标题相似的标题列表
    def titles_like(self, params):
        url = self.base_url + 'titles_like'
        resp = requests.get(url=url, params=params)
        print(resp.text)


if __name__ == "__main__":

    know = Knowledge()

    params = {
    "title": 'SLAM',
    }
    result = know.query_paper_metadata_that_title_contain(params=params)
    print(result)

    # know.test()
    # know.keywords_metadata()

    # 根据query检索论文片段
    '''params = {
            "query": "yolov11",
            "top_k": 5,
        }
    know.search_paper(params)'''

    # 根据论文id检索片段
    '''params = {
        "paper_id": "645d02d1d68f896efa8f0489",
        "top_k": 3
    }
    know.query_by_paper_id(params=params)'''


    # 根据论文title检索片段
    '''params = {
        "title": "Bi-calibration Networks for Weakly-Supervised Video Representation Learning",
        "top_k": 3
    }
    know.query_by_title(params=params)'''


    # 根据论文title检索标题中包含特定文本的论文片段
    """params = {
        "title": "Transformer AND LLM",
        "top_k": 3
    }
    know.query_by_title_contain(params=params)"""

    '''params = {
        "chunk": "we propose a deep neural network",
        "top_k": 3
    }
    know.query_by_chunk_contain(params=params)'''







# 数据库的基本信息
"""
{
    "paper_num": 17942,
    "chunk_num": 151816,
    "track_stats": {
        "total_track_nums": 49,
        "track_counts": {
            "Conf_Paper_Meta_Data_SIGIR2023_with_whole_text.db": 656,
            "Journal_Paper_Meta_Data_IEEE_Transactions_on_Pattern_Analysis_and_Machine_Intelligence_with_whole_text.db": 3275,
            "Conf_Paper_Meta_Data_NeurIPS_2023_with_whole_text.db": 950,
            "Conf_Paper_Meta_Data_AAAI_2023_with_whole_text.db": 523,
            "Conf_Paper_Meta_Data_IJCAI2024_with_whole_text.db": 2583,
            "Conf_Paper_Meta_Data_EMNLP_2023_with_whole_text.db": 4938,
            "Conf_Paper_Meta_Data_ICML2024_with_whole_text.db": 5623,
            "Journal_Paper_Meta_Data_IEEE_Transactions_on_Knowledge_and_Data_Engineering_with_whole_text.db": 901,
            "Conf_Paper_Meta_Data_ICLR2024_with_whole_text.db": 13174,
            "Conf_Paper_Meta_Data_WWW_2023__with_whole_text.db": 1557,
            "Conf_Paper_Meta_Data_IJCAI2023_with_whole_text.db": 2188,
            "Conf_Paper_Meta_Data_ECCV2024_with_whole_text.db": 13649,
            "Conf_Paper_Meta_Data_SIGIR2024_with_whole_text.db": 1140,
            "Conf_Paper_Meta_Data_ICML_2023_with_whole_text.db": 139,
            "Journal_Paper_Meta_Data_Journal_of_Machine_Learning_Research_with_whole_text.db": 489,
            "Journal_Paper_Meta_Data_Artificial_Intelligence_with_whole_text.db": 446,
            "Conf_Paper_Meta_Data_AAAI2024_with_whole_text.db": 11539,
            "Conf_Paper_Meta_Data_CVPR_2023_with_whole_text.db": 12242,
            "Journal_Paper_Meta_Data_International_Journal_of_Computer_Vision_with_whole_text.db": 434,
            "Conf_Paper_Meta_Data_ACL_2023_with_whole_text.db": 4943,
            "Conf_Paper_Meta_Data_ICLR_2023_with_whole_text.db": 7290,
            "Conf_Paper_Meta_Data_ICCV_2023_with_whole_text.db": 10389,
            "Conf_Paper_Meta_Data_CVPR2024_with_whole_text.db": 10804,
            "Conf_Paper_Meta_Data_ACL_2022_Annual_Meeting_of_the_Association_for_Computational_Linguistics_with_whole_text.db": 2811,
            "Conf_Paper_Meta_Data_ECAI_2023_with_whole_text.db": 482,
            "Conf_Paper_Meta_Data_Crypto_2023_with_whole_text.db": 261,
            "Conf_Paper_Meta_Data_CCS_2022_with_whole_text.db": 710,
            "Conf_Paper_Meta_Data_ECCV_2022_European_Conference_on_Computer_Vision_with_whole_text.db": 4539,
            "Conf_Paper_Meta_Data_Crypto_2022_with_whole_text.db": 46,
            "Conf_Paper_Meta_Data_CVPR_2022_IEEE_Conference_on_Computer_Vision_and_Pattern_Recognition_with_whole_text.db": 1304,
            "Conf_Paper_Meta_Data_EMNLP_2022_Empirical_Methods_in_Natural_Language_Processing_with_whole_text.db": 3079,
            "Conf_Paper_Meta_Data_ICML_2022_International_Conference_on_Machine_Learning_with_whole_text.db": 4336,
            "Conf_Paper_Meta_Data_ICLR_2022_International_Conference_on_Learning_Representation_with_whole_text.db": 3000,
            "Conf_Paper_Meta_Data_ISSTA_2022_with_whole_text.db": 111,
            "Conf_Paper_Meta_Data_IJCAI_2022_International_Joint_Conference_on_Artificial_Intelligence_with_whole_text.db": 916,
            "Conf_Paper_Meta_Data_MobiCom_2023_with_whole_text.db": 602,
            "Conf_Paper_Meta_Data_NeurIPS_2022_Neural_Information_Processing_Systems_with_whole_text.db": 12416,
            "Conf_Paper_Meta_Data_KDD2023_with_whole_text.db": 1710,
            "Conf_Paper_Meta_Data_SIGIR_2022_Special_Interest_Group_on_Information_Retrieval_with_whole_text.db": 528,
            "Conf_Paper_Meta_Data__STOC_2022_with_whole_text.db": 961,
            "Conf_Paper_Meta_Data_SP_2022_with_whole_text.db": 397,
            "Conf_Paper_Meta_Data_SIGMOD_2023_with_whole_text.db": 9,
            "Conf_Paper_Meta_Data_USENIX_Security_2023_with_whole_text.db": 460,
            "Conf_Paper_Meta_Data_SP_2023_with_whole_text.db": 335,
            "Conf_Paper_Meta_Data_VLDB2023_with_whole_text.db": 111,
            "Conf_Paper_Meta_Data_USENIX_Security_2022_with_whole_text.db": 668,
            "Conf_Paper_Meta_Data_STOC_2023_with_whole_text.db": 1167,
            "Conf_Paper_Meta_Data_VLDB_2022_with_whole_text.db": 215,
            "Conf_Paper_Meta_Data_WWW_2022_The_Web_Conference_with_whole_text.db": 770
        }
    }
}
"""